package com.example.demo.utils;

import com.example.demo.enums.ResultStatue;
import com.example.demo.vo.ResultVO;

/**
 * 响应参数封装
 * @date:2017/10/10
 * @time:16:36
 * @uthor:LYH
 */
public class ResultUtil {

    private ResultUtil(){}
    /**
     * 成功返回结果集
     * @param data 响应数据
     * @return ResultVO
     */
    public static ResultVO success(Object data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(ResultStatue.SUCCESS.getCode());
        resultVO.setMsg(ResultStatue.SUCCESS.getMsg());
        resultVO.setData(data);
        return resultVO;
    }
    /**
     * 成功返回结果集
     * @return ResultVO
     */
    public static ResultVO success() {
        return success(null);
    }
    /**
     * 失败返回结果集
     * @param resultStatue 错误码
     * @return ResultVO
     */
    public static ResultVO error(ResultStatue resultStatue) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(resultStatue.getCode());
        resultVO.setMsg(resultStatue.getMsg());
        resultVO.setData(null);
        return resultVO;
    }
    /**
     * 失败返回结果集
     * @return ResultVO
     */
    public static ResultVO error() {
        return error(ResultStatue.ERROE);
    }
}
